Service-based Dynamic Repeater Use Case

Scenario: Set up an Embedded Dynamic Repeater Dashboard and add multiple instances of the same components.

Role: Developer.

Benefits: Users can set up an Embedded Dynamic Repeater dashboard and add multiple instances of the same components without having to re-create each component individually.

Dynamic Dashboards can leverage templates to display similar items in the same dashboard, such as a list of icons or multiple grids. You can also trigger this from a Dynamic Dashboard Service Assembly file, which enables you to dynamically generate the list of items. For information on the standard no-code Repeater functionality, see Embedded Dynamic Repeater Dashboard.

You want to display user images and names in an Embedded Dynamic Repeater Dashboard. Complete these steps:

  1. Create an image component and a label component. See Component Display Format Properties. In this use case, each component is configured with template parameter values variables. These are populated by the RepeatArgs in the code. When the template runs, it is replaced with the actual image URL or name.

    The image component Url Or Full File Name property with template varible is boxed with yellow highlight.

    The label component Formatting Text property with template varible entered is boxed with yellow highlight.

  2. Create an Embedded Dashboard. See Dashboard Properties. In the Dashboard Components tab, add the image and label components to the Embedded Dashboard.

    The Dashboard Type property has Embedded selected and is outline with yellow highlight

    Image and Label components added to Dashboard Components and boxed with yellow highlight

  3. Create an Embedded Dynamic Repeater Dashboard. See Embedded Dynamic Repeater Dashboard. In the Dashboard Components tab, add the Embedded Dashboard Component. When the Embedded Dynamic Repeater Dashboard runs, it will repeat this Embedded Dashboard Component for each user. 0_Frame dashboard contains the Embedded Dashboard Components for 1_Title and 2_Content dashboards.

    The Dashboard Properties tab is open and the Dashboard Type is set to Embedded Dynamic Repeater which is boxed with yellow highlight

    Embedded Dashboard component is added in the Dashboard Components tab and boxed with yellow highlight

  4. In this use case, the Maintenance Unit's Workspace Assembly Service property is set to ITAssembly.MyServiceFactory. This property matches the ITAssembly Assembly which contains the MyServiceFactory Assembly file. This assembly will return the services.

    Maintenance Unit's Workspace Assembly Service property entry boxed with yellow highlight

    The Workspace Assembly Service property matches the ITAssemblyFile and Service Factory name

  5. In the MyServiceFactory Assembly file, the following code is the request you need to enable the processing of Dynamic Dashboards. This code returns what is set in the MyDynamicDashboardService file in the same Assembly.

    Code to enable processing of Dynamic Dashboards highlighted

     MyDynamicDashboardService Assembly file is highlighted

  6. The MyDynamicDashboardService Assembly file's default source code contains various automatically created methods. The core of the service is the GetEmbeddedDynamicDashboard function. Here, you can define the list of items you want repeated in the embedded dashboard. For example, the following code retrieves a list of users:

    Copy

    VB.Net

    ' retrieve our users
    Dim objGroupInfo As GroupInfo = BRApi.Security.Admin.GetGroup(si, "ITCrowd")
    Dim users As List(Of User) =
        objGroupInfo.ChildPrincipals.ConvertAll(
            Function(princ As Principal) BRApi.Security.Admin.GetUser(si, princ.UniqueID).User
        )

    If the data is a collection of basic types, like strings and integers, the simplest approach is to directly modify the ComponentTemplateRepeatItems property and add elements as required.

    Copy

    VB.Net

    ' get the dashboard
    Dim layoutDashboard = api.GetEmbeddedDynamicDashboard(si, workspace, parentDynamicComponentEx, _
        storedDashboard, String.Empty, Nothing, _
        TriStateBool.Unknown, WsDynamicItemStateType.Unknown)

    ' loop through users
    For Each myUser As User In users
        ' for each user, build an item definition with suffix and variable values
        Dim newTab = New XFDynamicDashboardTemplateItemDefinition( _
                    myUser.UniqueID.ToString, _
                    $"name={myUser.Name},photoUrl={myUser.Text1}")
        ' manipulate the dashboard property, adding our item
        layoutDashboard.DynamicDashboard.ComponentTemplateRepeatItems.Add(newTab)
    Next
    ' return the dashboard
    return layoutDashboard

    The following image displays the result. When this dashboard is run, it displays the corresponding user images and names.

    Design mode shows the Embedded Dynamic Repeater Dashboard has added multiple instances of the same components.

For more advanced configurations, you can use a complex technique based on the following principles:

  • Produce a list of WsDynamicComponentRepeatArgs objects that explicitly wrap each user.

  • Use the Tag property of the dashboard to make the list available to downstream functions.

    NOTE: The Tag property can be used as a conduit for any type of object, not just this list type.

This demonstration of the advanced configuration achieves the same results as the method presented in step 6.

  1. In the GetEmbeddedDynamicDashboard function, take the list of users and turn it into a list of WsDynamicComponentRepeatArgs.

    Copy

    VB.Net

    ' retrieve our users
    Dim objGroupInfo As GroupInfo = BRApi.Security.Admin.GetGroup(si, "ITCrowd")
    Dim users As List(Of User) =
        objGroupInfo.ChildPrincipals.ConvertAll(
            Function(princ As Principal) BRApi.Security.Admin.GetUser(si, princ.UniqueID).User
        )
    ' wrap each one in WsDynamicComponentRepeatArgs
    Dim repeatArgs As New List(Of WsDynamicComponentRepeatArgs)
    For Each userObj As User In users:
        Dim nextLevelTemplateSubstVarsToAdd As New Dictionary(Of String, String) _
            From { _
                {"name", userObj.Name}, _
                {"photoUrl", userObj.Text1} _
            }
        repeatArgs.Add( _
            New WsDynamicComponentRepeatArgs( _
                userObj.UniqueID.ToString, nextLevelTemplateSubstVarsToAdd))
    Next
  2. Place the list in the dashboard's Tag property.

    Copy

    VB.Net

    ' create the dashboard in memory
    Dim myDash As WsDynamicDashboardEx = api.GetEmbeddedDynamicDashboard(si, _
                                    workspace, parentDynamicComponentEx, _
                                    storedDashboard, String.Empty, Nothing, _
                                    TriStateBool.Unknown, WsDynamicItemStateType.Unknown)
                            
    ' Attach our List of repeaters. 
    myDash.DynamicDashboard.Tag = repeatArgs
    Return myDash
  3. In the GetDynamicComponentsForDynamicDashboards function, which is run further downstream by the system, retrieve the list of repeaters and use it to generate the components.

    Copy

    VB.Net

    ' retrieve the list of repeaters
    Dim repeatArgsList As List(Of WsDynamicComponentRepeatArgs) = dynamicDashboardEx.DynamicDashboard.Tag
                            
    Return api.GetDynamicComponentsRepeatedForDynamicDashboard(si, workspace, dynamicDashboardEx, _
        repeatArgsList,         ' our repeaters
        TriStateBool.TrueValue,     ' This is important! If set to False, dynamic Parameters won't be generated.
        WsDynamicItemStateType.MinimalWithTemplateParameters)   ' what to sync across server, keep minimal for perfomance